#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_nonuniform_qualifier : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

#include "../../../../core/shader_binding_ID.h"
#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"




layout(location=0) out vec4 outColor;

layout(set = 1, binding = DEF_BINDING_WIDGET_Texture) uniform sampler2D texColor[];

//材质属性
layout(std430, set = 2, scalar, column_major, binding = DEF_BINDING_TasterBindID_MaterialID) readonly buffer Buf4 {
	S_Material gMaterial[];
};



layout(location = 0) in vec3 inEyeDir;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec4 inVert;
layout(location = 3) in mat4 inCameraView;
layout(location = 7) in flat uint inMaterialID;


layout(early_fragment_tests) in;


void main(void){
	//outColor = vec4(vec3(dot(inEyeDir, inNormal)),1);
	//outColor = vec4(1);
	S_Material material = gMaterial[inMaterialID];
	
	float d = dot(normalize(vec3(inVert)), vec3(0,1,0));
	d += 2;
	d *= 0.3;
	//outColor.rgb = vec3(0.7,0.9,1.0) * d;
	outColor.rgb = material.m_color * d * material.m_emission;
	//outColor.rgb = normalize(vec3(inVert));
	outColor.a = 1;
	

	outColor.rgb += vec3(pow(dot(outColor.rgb, vec3(0.2125,0.7154,0.0721)), 5));

	/*
	if(gl_FragCoord.x > 1280/2){
		outColor.xyz = vec3((inCameraView * vec4(inVert.xyz, 0)).z * gl_FragCoord.w) * 0.5 + 0.5;
	}else{
		outColor.xyz = vec3((inCameraView * vec4(inVert.xyz, 0)).z);
	}
	*/
	
	//vec3 rv = reflect(normalize(-inEyeDir), inNormal);
	//outColor += texture(texEnv[0], rv) * 0.8;
	//outColor += texture(texEnv[0], normalize(inEyeDir));
	//outColor += texture(texEnv[0], inNormal);
	//if(inVert.z < 0){
	//	//outColor.xyz += normalize(inVert);
	//	outColor.z += 0.1;
	//}else{
	//
	//}
	//outColor += texture(texEnv[nonuniformEXT(0)], normalize(inVert)) * 0.8;
	
	//outColor.xyz += normalize(inEyeDir);
	//outColor.xyz += normalize(inNormal);
	//outColor.xyz += normalize(rv);
	//outColor += texture(texEnv[0], vec3(1,0,0));
}



